<?php

namespace App\Http\Controllers\System;


use App\Events\AccountEvent;
use App\Events\Event;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Model\System\Token;
use Laravel\Lumen\Routing\Controller as BaseController;

use App\Model\System\User;
use App\Http\Controllers\MessagePacket;

/**
 * eeo account check
 * Class AccountController
 * @package App\Http\Controllers\System
 */
class AccountController extends BaseController
{
    use MessagePacket;

    /**
     * 检查是否存在eeo账号
     * @param Request $request
     * @return array
     */
    function check(Request $request)
    {
        try{
            if(!$request->has('account')){
                return $this->fail(false,'参数不全');
            }

            $account = $request->get('account');
            $event = new AccountEvent($account, 0,0, Event::CHECK);
            event($event);
            return $this->success(true,"已经注册到EEO");
        }catch (\Exception $e){
            if($e->getMessage()=='OK'){
                return $this->success(false,"未注册到EEO");
            }else{
                return $this->fail(false,"检测失败：".$e->getMessage());
            }
        }
    }


    /**
     * 重置密码
     * @param Request $request
     * @return array
     */
    function  reset(Request $request)
    {
        try{
            if( !$request->has('account') or
                !$request->has('password')){
                return $this->fail(false,'参数不全');
            }

            $account = $request->get('account');
            $password = $request->get('password');

            $event = new AccountEvent($account, $password, 0, Event::RESET);
            event($event);
            return $this->success(true);
        }catch (\Exception $e){
            return $this->fail(false,"重置失败：".$e->getMessage());
        }
    }


}
